package com.tianji.remark.task;

import com.tianji.remark.service.ILikedRecordService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author Administrator
 * @version 1.0
 * @description: TODO
 * @date 2024/8/26 17:31
 */
@Slf4j
@Component
@RefreshScope
@RequiredArgsConstructor
public class LikeTimesCheckTask {
    private final ILikedRecordService likedRecordService;
    private static final List<String> BIZ_TYPES = List.of("QA","NOTE");
    //private static final Integer MAX_BIZ_SIZE = 30;
    @Value("${tj.likeTimes.maxBizSize}")
    private Integer maxBizSize;

    /**
     * 定时检测点赞数并发送业务方持久化消息
     */
    @Scheduled(fixedDelay = 20000)
    public void checkLikeTimes(){
        log.warn("当前处理任务数：" + maxBizSize);
        for (String bizType : BIZ_TYPES) {
            likedRecordService.readLikedTimesAndSendMessage(bizType,maxBizSize);
        }
    }
}
